/*******************************************************************************
 * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
 * @file     slideMenu.c
 * @author   UartTFT Application Team
 * @version  V0.0.1
 * @date     2023-01-11
 * @brief    This file provides UartTFT Application display function
 ********************************************************************************/

#include "slideMenu.h"
#include "data.h"
#include "bsp.h"

#include "uiIcon.h"
#include "popupBox.h"
#include "levetop.h"
#include "transport.h"
#include "uart.h"
#include "function_drv.h"


SldMenu_Info gSldMenu_Info[SLDMENU_SIZE];
//uint8_t SLDMfirsttouch = 0;
uint8_t sldmenu_count = 0, sldmenu_num = 0;
uint8_t sldmenu_flag = 0;
uint8_t sld_mum = 0;
uint8_t V_dev = 0;
uint16_t lastx = 0, lasty = 0, Sldw = 0, Sldh = 0;
uint16_t slide_wmax = 0;



/***********************************************************************************
 * Function Name : dp_menu
 * Description   : Display menu.
 * Input         : - num: which number of sliding menu
 * Output        : None
 * Return        : None
 ************************************************************************************/
void dp_menu(uint8_t num)
{
	uint8_t buff[12] = {0};
	uint16_t box_w, box_h, box_mw, box_mh;
	uint16_t cx,cy,cw;

	LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSldMenu_Info[num].frontID + multi_language * 12 * addr_index[11], 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	Sldw = buff[4] + (buff[5] << 8);
	Sldh = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];

	PICINFO[1].addr = pic_add;
	PICINFO[1].w = Sldw;
	PICINFO[1].h = Sldh;
	PICINFO[1].len = pic_len;
	PICINFO[1].flag = pic_flag;

	LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSldMenu_Info[num].bgID + multi_language * 12 * addr_index[11], 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	Sldw = buff[4] + (buff[5] << 8);
	Sldh = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];

	PICINFO[0].addr = pic_add;
	PICINFO[0].w = Sldw;
	PICINFO[0].h = Sldh;
	PICINFO[0].len = pic_len;
	PICINFO[0].flag = pic_flag;


	box_w = gSldMenu_Info[num].Xe - gSldMenu_Info[num].Xs;
	box_h = gSldMenu_Info[num].Ye - gSldMenu_Info[num].Ys;

	if (pic_update == 0)
	{
		cx = 0;
		cy = 0;
		cw = box_w;
	}
	else
	{
		cx = gSldMenu_Info[num].Xs;
		cy = gSldMenu_Info[num].Ys;
		cw = FullScreen_w;
	}


	if ((gSldMenu_Info[num].dir & 0x01) == 0) // up and down
	{
		if (gSldMenu_Info[num].pos > Sldh)
			gSldMenu_Info[num].pos = Sldh;

		//box_h = gSldMenu_Info[num].Ye - gSldMenu_Info[num].Ys;
		box_mh = box_h - gSldMenu_Info[num].L1 - gSldMenu_Info[num].L2;

		if (gSldMenu_Info[num].pos == 0 || gSldMenu_Info[num].pos == Sldh)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				{
					if (pic_update == 0)
						LT268_BG_to_buffer(0, 0, cw, m_PngData,
											gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
				}
				LT268_pic_to_buffer(cx, cy, cw, m_PngData,
									0, Sldh - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(cx, cy + box_h - gSldMenu_Info[num].L2, cw, m_PngData,
									0, box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(cx, cy + gSldMenu_Info[num].L1, cw, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < gSldMenu_Info[num].L1)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				{
					if (pic_update == 0)
					LT268_BG_to_buffer(0, 0, cw, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
				}
				LT268_pic_to_buffer(cx, cy, cw, m_PngData,
									0, Sldh - (gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos), PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, PICINFO[0].flag);
				LT268_pic_to_buffer(cx, cy + gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, cw, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].pos, PICINFO[0].flag);

				LT268_pic_to_buffer(cx, cy + box_h - gSldMenu_Info[num].L2, cw, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(cx, cy + gSldMenu_Info[num].L1, cw, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldh - (box_h - gSldMenu_Info[num].L1))) // In the middle
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				{
					if (pic_update == 0)
						LT268_BG_to_buffer(0, 0, cw, m_PngData,
											gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
				}
				LT268_pic_to_buffer(cx, cy, cw, m_PngData,
									0, gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(cx, cy + box_h - gSldMenu_Info[num].L2, cw, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(cx, cy + gSldMenu_Info[num].L1, cw, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldh - box_mh))
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				{
					if (pic_update == 0)
					LT268_BG_to_buffer(0, 0, cw, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
				}
				LT268_pic_to_buffer(cx, cy, cw, m_PngData,
									0, gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(cx, cy + box_h - gSldMenu_Info[num].L2, cw, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, Sldh - (gSldMenu_Info[num].pos + box_mh), PICINFO[0].flag);
				LT268_pic_to_buffer(cx, cy + box_h - gSldMenu_Info[num].L2 + Sldh - (gSldMenu_Info[num].pos + box_mh), cw, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2 - (Sldh - (gSldMenu_Info[num].pos + box_mh)), PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(cx, cy + gSldMenu_Info[num].L1, cw, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < Sldh)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{

				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				{
					if (pic_update == 0)
						LT268_BG_to_buffer(0, 0, cw, m_PngData,
											gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
				}
				LT268_pic_to_buffer(cx, cy, cw, m_PngData,
									0, gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L1, PICINFO[0].flag);

				LT268_pic_to_buffer(cx, cy + box_h - gSldMenu_Info[num].L2, cw, m_PngData,
									0, gSldMenu_Info[num].pos + box_mh - Sldh, PICINFO[0].w, PICINFO[0].addr,
									PICINFO[0].w, gSldMenu_Info[num].L2, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(cx, cy + gSldMenu_Info[num].L1, cw, m_PngData,
										0, gSldMenu_Info[num].pos, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, Sldh - gSldMenu_Info[num].pos, PICINFO[1].flag);
					LT268_pic_to_buffer(cx, cy + gSldMenu_Info[num].L1 + Sldh - gSldMenu_Info[num].pos, cw, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										PICINFO[1].w, box_mh - (Sldh - gSldMenu_Info[num].pos), PICINFO[1].flag);
				}
			}
		}

		// display
		if (pic_update == 0)
			LT268_buffer_to_TFT(0, 0, cw, m_PngData,
								gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, PICINFO[0].w, box_h);
	}
	else if ((gSldMenu_Info[num].dir & 0x01) == 1) // the left and right sides
	{
		if (gSldMenu_Info[num].pos > Sldw)
			gSldMenu_Info[num].pos = Sldw;
//		box_w = gSldMenu_Info[num].Xe - gSldMenu_Info[num].Xs;
//		box_h = gSldMenu_Info[num].Ye - gSldMenu_Info[num].Ys;
		box_mw = box_w - gSldMenu_Info[num].L1 - gSldMenu_Info[num].L2;

		if (gSldMenu_Info[num].pos == 0 || gSldMenu_Info[num].pos == Sldw)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				{
					if (pic_update == 0)
						LT268_BG_to_buffer(0, 0, cw, m_PngData,
											gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
				}
				LT268_pic_to_buffer(cx, cy, cw, m_PngData,
									Sldw - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(cx + box_w - gSldMenu_Info[num].L2, cy, cw, m_PngData,
									box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(cx + gSldMenu_Info[num].L1, cy, cw, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < gSldMenu_Info[num].L1)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				{
					if (pic_update == 0)
						LT268_BG_to_buffer(0, 0, cw, m_PngData,
											gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
				}
				LT268_pic_to_buffer(cx, cy, cw, m_PngData,
									Sldw - (gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos), 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, box_h, PICINFO[0].flag);
				LT268_pic_to_buffer(cx + gSldMenu_Info[num].L1 - gSldMenu_Info[num].pos, cy, cw, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].pos, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(cx + box_w - gSldMenu_Info[num].L2, cy, cw, m_PngData,
									gSldMenu_Info[num].pos + box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(cx + gSldMenu_Info[num].L1, cy, cw, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldw - (box_w - gSldMenu_Info[num].L1))) // In the middle
		{

			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				{
					if (pic_update == 0)
						LT268_BG_to_buffer(0, 0, cw, m_PngData,
											gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
				}

				LT268_pic_to_buffer(cx, cy, cw, m_PngData,
									gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(cx + box_w - gSldMenu_Info[num].L2, cy, cw, m_PngData,
									gSldMenu_Info[num].pos + box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(cx + gSldMenu_Info[num].L1, cy, cw, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos <= (Sldw - box_mw))
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				{
					if (pic_update == 0)
						LT268_BG_to_buffer(0, 0, cw, m_PngData,
											gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
				}
				LT268_pic_to_buffer(cx, cy, cw, m_PngData,
									gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(cx + box_w - gSldMenu_Info[num].L2, cy, cw, m_PngData,
									gSldMenu_Info[num].pos + box_mw, 0, PICINFO[0].w, PICINFO[0].addr,
									Sldw - (gSldMenu_Info[num].pos + box_mw), box_h, PICINFO[0].flag);
				LT268_pic_to_buffer(cx + box_w - gSldMenu_Info[num].L2 + Sldw - (gSldMenu_Info[num].pos + box_mw), cy, cw, m_PngData,
									0, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2 - (Sldw - (gSldMenu_Info[num].pos + box_mw)), box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(cx + gSldMenu_Info[num].L1, cy, cw, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw, box_h, PICINFO[1].flag);
				}
			}
		}
		else if (gSldMenu_Info[num].pos < Sldw)
		{
			if (PICINFO[0].len != 0 && PICINFO[0].flag != 0xFF)
			{
				if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
				{
					if (pic_update == 0)
						LT268_BG_to_buffer(0, 0, cw, m_PngData,
										gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
				}
				LT268_pic_to_buffer(cx, cy, cw, m_PngData,
									gSldMenu_Info[num].pos - gSldMenu_Info[num].L1, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L1, box_h, PICINFO[0].flag);

				LT268_pic_to_buffer(cx + box_w - gSldMenu_Info[num].L2, cy, cw, m_PngData,
									gSldMenu_Info[num].pos + box_mw - Sldw, 0, PICINFO[0].w, PICINFO[0].addr,
									gSldMenu_Info[num].L2, box_h, PICINFO[0].flag);

				if (PICINFO[1].len != 0 && PICINFO[1].flag != 0xFF)
				{
					LT268_pic_to_buffer(cx + gSldMenu_Info[num].L1, cy, cw, m_PngData,
										gSldMenu_Info[num].pos, 0, PICINFO[1].w, PICINFO[1].addr,
										Sldw - gSldMenu_Info[num].pos, box_h, PICINFO[1].flag);
					LT268_pic_to_buffer(cx + gSldMenu_Info[num].L1 + Sldw - gSldMenu_Info[num].pos, cy, cw, m_PngData,
										0, 0, PICINFO[1].w, PICINFO[1].addr,
										box_mw - (Sldw - gSldMenu_Info[num].pos), box_h, PICINFO[1].flag);
				}
			}
		}
		// display
		if (pic_update == 0)
			LT268_buffer_to_TFT(0, 0, cw, m_PngData,
							gSldMenu_Info[num].Xs, gSldMenu_Info[num].Ys, box_w, box_h);
	}
}

/***********************************************************************************
 * Function Name : DL_menu
 * Description   : Get info of sliding menu.
 * Input         : - num: which number of sliding menu
 * Output        : None
 * Return        : None
 ************************************************************************************/
void DL_menu(uint8_t num)
{
	uint8_t buff[12] = {0};

	LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSldMenu_Info[num].frontID + multi_language * 12 * addr_index[11], 12);
	pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
	Sldw = buff[4] + (buff[5] << 8);
	Sldh = buff[6] + (buff[7] << 8);
	pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
	pic_flag = buff[11];

	gSldMenu_Info[num].flag = pic_flag;

}




/***********************************************************************************
 * Function Name : slideMune
 * Description   : Touch detection of slding menu.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
void slideMenu(void)
{
	uint8_t i = 0;
	uint8_t rebuf[20];
	uint16_t temp, sum, V=0;
	uint16_t dev = 0;
	int16_t df = 0;

	// press down
	if (gTpInfo.sta)
	{
		for (i = 0; i < sldmenu_count; i++)
		{

			if ((sldmenu_flag == 1) || (gTpInfo.x[0] >= gSldMenu_Info[i].Xs && gTpInfo.y[0] >= gSldMenu_Info[i].Ys &&
				gTpInfo.x[0] <= gSldMenu_Info[i].Xe && gTpInfo.y[0] <= gSldMenu_Info[i].Ye && button_Press_flag == 0 )  )
			{

				if (sldmenu_flag == 0) // First press
				{
					DL_menu(i);
					lastx = gTpInfo.x[0];
					lasty = gTpInfo.y[0];
					sldmenu_num = i;
					sldmenu_flag = 1;
					button_Press_flag = 1;
					if (buzzer)
						touch_buzzer();
					V_dev = 0;
				}
				else // Sliding treatment
				{
					if ((gSldMenu_Info[sldmenu_num].dir & 0x01) == 0) // up and down
					{
						df = lasty - gTpInfo.y[0];
						gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos + df;

						if (gSldMenu_Info[sldmenu_num].dir == 0x80)
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = 0;
							if (gSldMenu_Info[sldmenu_num].pos > (Sldh - dev - (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2)))
								gSldMenu_Info[sldmenu_num].pos = Sldh - dev - (gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
						}
						else
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = Sldh - dev + gSldMenu_Info[sldmenu_num].pos;
							if (gSldMenu_Info[sldmenu_num].pos > (Sldh - dev))
								gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos - (Sldh - dev);
						}
						if (df != 0)
						{
							dp_menu(sldmenu_num);
							lasty = gTpInfo.y[0];
						}
					}
					else if ((gSldMenu_Info[sldmenu_num].dir & 0x01) == 1) // the left and right
					{
						df = lastx - gTpInfo.x[0];
						gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos + df;

						if (gSldMenu_Info[sldmenu_num].dir == 0x81)
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = 0; // in range
							if (gSldMenu_Info[sldmenu_num].pos > (Sldw - dev - (gSldMenu_Info[sldmenu_num].Xe - gSldMenu_Info[sldmenu_num].Xs - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2)))
								gSldMenu_Info[sldmenu_num].pos = Sldw - dev - (gSldMenu_Info[sldmenu_num].Xe - gSldMenu_Info[sldmenu_num].Xs - gSldMenu_Info[sldmenu_num].L1 - gSldMenu_Info[sldmenu_num].L2);
						}
						else
						{
							if (gSldMenu_Info[sldmenu_num].pos < 0)
								gSldMenu_Info[sldmenu_num].pos = Sldw - dev + gSldMenu_Info[sldmenu_num].pos; // in range
							if (gSldMenu_Info[sldmenu_num].pos > (Sldw - dev))
								gSldMenu_Info[sldmenu_num].pos = gSldMenu_Info[sldmenu_num].pos - (Sldw - dev);
						}
						if (df != 0)
						{
							dp_menu(sldmenu_num);
							lastx = gTpInfo.x[0];
						}
					}
				}
			}
		}
	}
	// raise
	else if (sldmenu_flag == 1 && (gTpInfo.sta == 0 ||
	 							   !(gTpInfo.x[0] >= gSldMenu_Info[sldmenu_num].Xs && gTpInfo.y[0] >= gSldMenu_Info[sldmenu_num].Ys &&
	 								 gTpInfo.x[0] <= gSldMenu_Info[sldmenu_num].Xe && gTpInfo.y[0] <= gSldMenu_Info[sldmenu_num].Ye))) // ����
	{
//		SLDMfirsttouch = 0;
		if ((gSldMenu_Info[sldmenu_num].dir & 0x01) == 0) // up and down
			temp = gSldMenu_Info[sldmenu_num].Ye - gSldMenu_Info[sldmenu_num].Ys - gSldMenu_Info[sldmenu_num].L2 - gSldMenu_Info[sldmenu_num].L1;
		else // left and right
			temp = gSldMenu_Info[sldmenu_num].Xe - gSldMenu_Info[sldmenu_num].Xs - gSldMenu_Info[sldmenu_num].L2 - gSldMenu_Info[sldmenu_num].L1;
					V_dev = 0;

		if ((gSldMenu_Info[sldmenu_num].pos % temp) > (temp / 2))
		{
			V = (gSldMenu_Info[sldmenu_num].pos / temp + 1) * gSldMenu_Info[sldmenu_num].step + gSldMenu_Info[sldmenu_num].V_min;
			gSldMenu_Info[sldmenu_num].pos = (V - gSldMenu_Info[sldmenu_num].V_min) / gSldMenu_Info[sldmenu_num].step * temp;
			if (V > gSldMenu_Info[sldmenu_num].V_max - V_dev)
				V = gSldMenu_Info[sldmenu_num].V_min;


		}
		else
		{
			V = (gSldMenu_Info[sldmenu_num].pos / temp) * gSldMenu_Info[sldmenu_num].step + gSldMenu_Info[sldmenu_num].V_min;
			gSldMenu_Info[sldmenu_num].pos = (V - gSldMenu_Info[sldmenu_num].V_min) / gSldMenu_Info[sldmenu_num].step * temp;
			if (V > gSldMenu_Info[sldmenu_num].V_max - V_dev)
				V = gSldMenu_Info[sldmenu_num].V_min;

		}

		if ((gSldMenu_Info[sldmenu_num].dir & 0x01) == 0)
		{
			if (Screen_DIR == 3 ||  Screen_DIR == 2)
				V = gSldMenu_Info[sldmenu_num].V_max - V + gSldMenu_Info[sldmenu_num].V_min;
		}
		else
		{
			if (Screen_DIR == 1 ||  Screen_DIR == 2)
				V = gSldMenu_Info[sldmenu_num].V_max - V + gSldMenu_Info[sldmenu_num].V_min;
		}

		var[gSldMenu_Info[sldmenu_num].p_add * 2] = (V >> 8) & 0xFF;
		var[gSldMenu_Info[sldmenu_num].p_add * 2 + 1] = V & 0xFF;

		if (gSldMenu_Info[sldmenu_num].Code == 0xC006)
		{
			rebuf[3] = 0x41;
			rebuf[4] = gSldMenu_Info[sldmenu_num].p_add >> 8;
			rebuf[5] = gSldMenu_Info[sldmenu_num].p_add & 0xFF;
			rebuf[6] = var[gSldMenu_Info[sldmenu_num].p_add * 2];
			rebuf[7] = var[gSldMenu_Info[sldmenu_num].p_add * 2 + 1];
			Var_AddrToReg(&rebuf[4]);
			LT_SendData_CRC_Frame(rebuf, 5);
		}

		dp_menu(sldmenu_num);
		if (gSldMenu_Info[sldmenu_num].p_add >= VAR_ADDR_S)
			reg_operation(gSldMenu_Info[sldmenu_num].p_add);

		page_date_update(pic_id);
		sldmenu_flag = 0;
		button_Press_flag = 0;
	}

}
